package com.txunda.zhuohired.adapter.manage.my;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.bean.manage.my.ManageResumeCollectBean;
import com.txunda.zhuohired.util.GlideCircleTransform;

import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/8 13:21
 * 功能描述：我的收藏adapter
 * 联系方式：jiahuanchen@126.com
 */

public class ManageResumeCollectAdapter extends BaseAdapter {
    private Context context;
    private int collectStatus;
    private ViewHolder holder;

    /**
     * 自定义监听
     */
    private HolderClickListener mHolderClickListener;
    private List<ManageResumeCollectBean.DataBean> list;

    public ManageResumeCollectAdapter(Context context, int collectStatus,
                                      List<ManageResumeCollectBean.DataBean> list) {
        this.collectStatus = collectStatus;
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_manage_resume_collect, null);
            holder = new ViewHolder();
            view.setTag(holder);
            ViewUtils.inject(holder, view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        if (collectStatus == 1) {
            holder.iv_item_resume_collect_delete.setVisibility(View.GONE);
        } else {
            holder.iv_item_resume_collect_delete.setVisibility(View.VISIBLE);
            holder.iv_item_resume_collect_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mHolderClickListener.onSureHolderClick(i);
                }
            });
        }
        holder.tv_item_manage_headname.setText(list.get(i).getName());
        holder.tv_item_manage_info.setText(list.get(i).getSex()+"  "+list.get(i).getWorktime()
                +"  "+list.get(i).getEducation_name());
        holder.tv_item_manage_work.setText(list.get(i).getTrade());
        holder.tv_item_manage_xinzi.setText(list.get(i).getPrice());
//        holder.tv_item_manage_content.setText(list.get(i).get);
        Glide.with(context).load(list.get(i).getHead_pic())
                .dontAnimate()
                .error(R.mipmap.default_image)
                .placeholder(R.mipmap.default_image)
                .transform(new GlideCircleTransform(context))
                .into(holder.iv_item_manage_home_list);
        return view;
    }

    class ViewHolder {
        @ViewInject(R.id.iv_item_resume_collect_delete)
        private ImageView iv_item_resume_collect_delete;
        @ViewInject(R.id.iv_item_manage_home_list)
        private ImageView iv_item_manage_home_list;
        @ViewInject(R.id.tv_item_manage_headname)
        private TextView tv_item_manage_headname;
        @ViewInject(R.id.tv_item_manage_info)
        private TextView tv_item_manage_info;
        @ViewInject(R.id.tv_item_manage_xinzi)
        private TextView tv_item_manage_xinzi;
        @ViewInject(R.id.tv_item_manage_work)
        private TextView tv_item_manage_work;
        @ViewInject(R.id.tv_item_manage_content)
        private TextView tv_item_manage_content;
    }

    /**
     * 自定义监听
     *
     * @param holderClickListener
     */
    public void SetOnClickListener(HolderClickListener holderClickListener) {
        this.mHolderClickListener = holderClickListener;
    }

    /**
     * 自定义监听
     */
    public interface HolderClickListener {
        void onSureHolderClick(int position);

    }
}
